home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / CDEF Source / source / cdefSpinner.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.0 KB  |  116 lines  |  [TEXT/KAHL]

  1. //------------------------- © 1992-1995 by James G. Stout --------------------------
  2. // File        : cdefSpinner.h
  3. // Date        : 24 October 1992
  4. // Author    : Jim Stout
  5. //            :
  6. // Purpose    : a "Spinner Control" CDEF that allows adjustment of a
  7. //            : number via an up/down spinner - a "little arrow" control as 
  8. //            : described in the Inside Mac volume on human interface.
  9. //            :
  10. //            : ControlMin and Max are respected, as is the useWindFont variation.
  11. //            : Inactive controls are drawn in the proper gray color or pattern.
  12. //            :
  13. //            : Normally, the control value will be incremented by 1.  To change
  14. //            : this, just set the refCon in your template or call to NewControl
  15. //            : to the desired increment value.
  16. //            :
  17. //            : If the mouse held down in the control, it will "accelerate" and
  18. //            : the control value will change by larger and larger increments.
  19. //            : If the increment is 1, it will change by 1's from 1-50, then
  20. //            : by 10's from 50-100, then by 100's.
  21. //            : 
  22. //            : The default arrow type is like the ones in the Date & Time control
  23. //            : panel.  A variation code of 1 will give larger arrows, as in the
  24. //            : Memory Control panel. A variation code of 2 will produce 3D arrows
  25. //            : and variation code 4 can be used for horizontal arrows
  26. //            :
  27. //            : The control title will be drawn left justified, the up/down
  28. //            : arrows will be drawn right justified, with the control value
  29. //            : number drawn just to the left of the arrows. 
  30. //            :
  31. //            : The minimum size for this control is 18 pixels x 11 pixels for
  32. //            : small arrows or 25 pixels by 15 pixels for the larger (variation 1).
  33. //            : Set to this size to use with an edit text control as discussed below.
  34. //            : Set to these minima, the control title and value will not be drawn.
  35. //            :
  36. //            : This CDEF can be used in conjunction with a dialog edit text item.
  37. //            : CDEFs cannot get keyDown events, so the trick here is to have the
  38. //            : CDEF update the edit text item.  To do this, set the HiWord of
  39. //            : control refCon to a DITL editText item number to be updated.  In
  40. //            : this case, set the LoWord of the refCon to the desired increment.
  41. //            :
  42. //            : The calling program must take care of insuring that only digits
  43. //            : are typed into the edit text. ALSO, when the user types new
  44. //            : digits, the calling program must get the contents of the edit item,
  45. //            : convert it to a number and call SetCtlValue to let the control
  46. //            : know about the new value.  Otherwise, the next click in the 
  47. //            : control will wipe out the typed value.
  48. //            :
  49. //            : use procID :   102 * 16 + varCode 
  50. //            :      when calling NewControl() or in your resource template.
  51. //
  52. //----------------------------------------------------------------------------------
  53.  
  54. #define ARROWHT        18                // the size of the little arrows
  55. #define ARROWID        11
  56. #define ARROWHT1    25                // the size of the big arrows
  57. #define ARROWID1    15
  58.  
  59. //----------------------------------------------------------------------------------
  60. // variation codes    
  61. //----------------------------------------------------------------------------------
  62. #define bigArrows        0x01
  63. #define ctl3D            0x02
  64. #define horizArrows        0x04
  65. #ifndef useWindFont        
  66. #define useWindFont        0x08        // draw with window font instead of System font
  67. #endif
  68.  
  69. //----------------------------------------------------------------------------------
  70. // partCodes    
  71. //----------------------------------------------------------------------------------    
  72.  
  73. enum {
  74. ALL = 0,
  75. FRAME,
  76. UPARROW,
  77. DOWNARROW,
  78. TITLE,
  79. BASELINE,
  80. NUMPARTS
  81. };
  82.  
  83. //----------------------------------------------------------------------------------
  84. // CDEF private data structure    
  85. //----------------------------------------------------------------------------------
  86.  
  87. typedef struct {
  88.  
  89. //  increment and DITL itemNum are passed into the control as 
  90. //    LoWord & HiWord of the control RefCon            
  91.     
  92. short        increment;            // initial, requested increment value    
  93. short        itemNum;            // DITL editText item number for SetIText
  94. long        userData;            // user supplied data    
  95. short        currIncr;            // current increment value                        
  96. short        bumpit;                // when == 1, bump increment up                
  97. short        qdVers;                // QuickDraw version                        
  98. short        pDepth;                // pixel depth for control
  99. CGrafPtr    offPort;            // offscreen drawing port        
  100. PolyHandle    poly[3];            // for arrow frame & arrows        
  101. }spinData,**hSpinData;
  102.  
  103. //----------------------------------------------------------------------------------
  104. //    Function prototypes
  105. //----------------------------------------------------------------------------------
  106.  
  107. static void doInit            (ControlHandle theControl, short varCode);
  108. static void doDisp            (ControlHandle theControl);
  109. static long doTest            (ControlHandle theControl, short varCode, long param);
  110. static void updateValue        (ControlHandle theControl, short partCode);
  111. static void makePolys        (ControlHandle theControl, short varCode);
  112. static void doDraw            (ControlHandle theControl, short varCode);
  113. static void drawArrows        (ControlHandle theControl, short varCode, short partCode,
  114.                                 Boolean inactive, Boolean inColor);
  115. static void getRects        (ControlHandle theControl, short varCode, Rect r1[]);
  116. static void accelerate        (ControlHandle theControl);